package com.machinsight.library.action;

import com.machinsight.library.bean.LoginUser;
import com.machinsight.library.content.ContentValue;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Copyright ©2017-2020 Machinsight Technology Co., Ltd.All rights reserved.
 * Author: Zhoushaohua
 * Date: 2020/1/2
 * Description:采用AXAJ技术的Action
 */
public class AjaxLoginAction {
    private final static String ROOT_NAME = "root";
    private final static String ROOT_PWD = "123456";
    private LoginUser user;
    private String msg;

    public String doLogin() {
        //获取HttpServletRequest对象
        HttpServletRequest request = ServletActionContext.getRequest();
        //这里的key值"username"、"password"与表单中的一致
        String username = request.getParameter("account");
        String pwd = request.getParameter("password");
        System.out.println("username : " + username + " and pwd : " + pwd);
        if (!ROOT_NAME.equals(username) || !ROOT_PWD.equals(pwd)) {
            msg = "账户或密码输入错误";
            return ContentValue.EXCEPTION;
        }
        user = new LoginUser();
        user.setName(username);
        user.setPassword(pwd);
        return ContentValue.SUCCESS;
    }

    public LoginUser getUser() {
        return user;
    }

    public void setUser(LoginUser user) {
        this.user = user;
    }
}
